using System.Net;

namespace Beetle;

public class IpItem
{
	private bool a = true;

	private bool b;

	private byte[] c;

	private byte[] d;

	private string e;

	public bool Permit => a;

	public string AddressValue => e;

	public IpItem(IPAddress ip)
	{
		c = ip.GetAddressBytes();
	}

	public IpItem(IPAddress startip, IPAddress endip)
	{
		c = startip.GetAddressBytes();
		d = endip.GetAddressBytes();
		b = true;
	}

	public IpItem(IPAddress startip, IPAddress endip, bool permit)
	{
		c = startip.GetAddressBytes();
		d = endip.GetAddressBytes();
		b = true;
		a = true;
	}

	public bool Verification(IPAddress ip)
	{
		bool flag = false;
		byte[] addressBytes = ip.GetAddressBytes();
		flag = ((!b) ? ((addressBytes[0] == c[0]) & (addressBytes[1] == c[1]) & (addressBytes[2] == c[2]) & (addressBytes[3] == c[3])) : (addressBytes[0] >= c[0] && ((addressBytes[0] <= d[0]) & (addressBytes[1] >= c[1])) && ((addressBytes[0] <= d[1]) & (addressBytes[2] >= c[2])) && ((addressBytes[0] <= d[2]) & (addressBytes[3] >= c[3])) && addressBytes[0] <= d[3]));
		if (a)
		{
			return flag;
		}
		return !flag;
	}

	public static IpItem From(string ipaddress, bool permit)
	{
		IpItem ipItem = null;
		IPAddress address = null;
		IPAddress address2 = null;
		string[] array = ipaddress.Split('-');
		if (array.Length == 2)
		{
			if (IPAddress.TryParse(array[0], out address) && IPAddress.TryParse(array[1], out address2))
			{
				ipItem = new IpItem(address, address2, permit);
				ipItem.e = ipaddress;
			}
		}
		else if (IPAddress.TryParse(array[0], out address))
		{
			ipItem = new IpItem(address);
			ipItem.a = permit;
			ipItem.e = ipaddress;
		}
		return ipItem;
	}
}
